package com.company.Hard;

import java.util.Stack;

public class LK32 {
    public static void main(String[] args) {
        System.out.println(longestValidParentheses(")("));
        //"(()()()((())(((()()("
    }
    public static int longestValidParentheses(String s) {
        int sum = 0;
        Stack<Integer> stack = new Stack<>();
        char[] arr = s.toCharArray();
        for(int i=0;i<arr.length;i++){
            if(arr[i]=='('){
             stack.add(1);
            }else{
                if(stack.size()!=0){
                    stack.pop();
                    sum += 2;
                }
            }
        }
        return sum;

    }
}
